import java.net.*;
import java.io.*;
 
public class Listener implements Runnable {
	private static final int port = 7789;
	private static final int maxConnections = 900;
	private static int connections = 0;

	
	public Listener() {
    	Thread t = new Thread(this);
    	t.start();
    }
    
    public void run() {
    	try {
    		ServerSocket sock = new ServerSocket(port);
    		Socket clientSocket;
    		
    		// Listen for connection
    		while(connections < maxConnections) {
    			clientSocket = sock.accept();
    			connections++;
    			System.out.println(connections);
    			ClientThread client = new ClientThread(clientSocket,connections);
    			Thread tread = new Thread(client);
    			tread.start();
    			
    		}
    		sock.accept();
    		System.out.println("Server is full.");
    		sock.close();
	    } catch (IOException e){
	    	System.err.println(e);
	    }
    }
		
}